package com.zrwl.poscloud.core.restapi.admin.baseInfo;
import com.zrwl.poscloud.core.annotion.AuthorityVerify.AuthorityVerify;
import com.zrwl.poscloud.core.annotion.OperationLogger.OperationLogger;
import com.zrwl.poscloud.commons.exception.ThrowableUtils;
import com.zrwl.poscloud.commons.utils.ResultUtil;
import com.zrwl.poscloud.commons.validator.group.Delete;
import com.zrwl.poscloud.commons.validator.group.GetList;
import com.zrwl.poscloud.commons.validator.group.Insert;
import com.zrwl.poscloud.commons.validator.group.Update;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zrwl.poscloud.xo.service.UserServiceOrderService;
import com.zrwl.poscloud.xo.vo.UserServiceOrderVO;

import java.util.Date;

/**
 * 服务采购 controller api类
 *
 * @author 刘思童 AutoGenerate
 * @date 2023-02-28
 */
@RestController
@Api(value = "服务采购相关接口", tags = {"服务采购相关接口"})
@RequestMapping("/userServiceOrder")
@Slf4j
public class UserServiceOrderRestApi {
    @Autowired
    private UserServiceOrderService userServiceOrderService;
    @AuthorityVerify
    @ApiOperation(value = "获取服务采购列表", notes = "获取服务采购列表", response = String.class)
    @PostMapping("/getList")
    public String getList(@Validated({GetList.class}) @RequestBody UserServiceOrderVO userServiceOrderVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取服务采购列表: {}", userServiceOrderVO);
        return ResultUtil.successWithData(userServiceOrderService.getPageList(userServiceOrderVO));
    }

    @AuthorityVerify
    @ApiOperation(value = "获取服务采购列表", notes = "获取服务采购列表", response = String.class)
    @PostMapping("/getAllList")
    public String getAllList(@Validated({GetList.class}) @RequestBody UserServiceOrderVO userServiceOrderVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取服务采购列表: {}", userServiceOrderVO);
        return ResultUtil.successWithData(userServiceOrderService.getAllList(userServiceOrderVO));
    }

    @AuthorityVerify
    @OperationLogger(value = "新增服务采购")    @ApiOperation(value = "新增服务采购", notes = "新增服务采购", response = String.class)
    @PostMapping("/add")
    public String add(@Validated({Insert.class}) @RequestBody UserServiceOrderVO userServiceOrderVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("新增服务采购: {}", userServiceOrderVO);
        return userServiceOrderService.add(userServiceOrderVO);
    }
    @AuthorityVerify
    @OperationLogger(value = "获取用户订单编号")
    @ApiOperation(value = "获取用户订单编号", notes = "获取用户订单编号", response = String.class)
    @PostMapping("/getAutoOrderCode")
    public String getAutoOrderCode(){
        log.info("获取用户订单编号" + new Date());
        return ResultUtil.successWithData(userServiceOrderService.getAutoOrderCode());
    }
    @AuthorityVerify
    @OperationLogger(value = "修改服务采购")    @ApiOperation(value = "修改服务采购", notes = "修改服务采购", response = String.class)
    @PostMapping("/edit")
    public String edit(@Validated({Update.class}) @RequestBody UserServiceOrderVO userServiceOrderVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("修改服务采购: {}", userServiceOrderVO);
        return userServiceOrderService.edit(userServiceOrderVO);
    }

    @AuthorityVerify
    @OperationLogger(value = "删除服务采购")    @ApiOperation(value = "删除服务采购", notes = "删除服务采购", response = String.class)
    @PostMapping("/delete")
    public String delete(@Validated({Delete.class}) @RequestBody UserServiceOrderVO userServiceOrderVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("删除服务采购: {}", userServiceOrderVO);
        return userServiceOrderService.delete(userServiceOrderVO);
    }

}
